﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PM.Web
{
    public partial class ServicesAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["type"] == "2")
                {
                    this.litTitle.Text = "投诉单";
                    this.panRepair.Visible = false;
                    this.panComp.Visible = true;
                }
                bindData();
            }
        }

        private void bindData()
        {
            this.txtHomeTel.Text = Convert.ToString(Session["Tel"]);
            this.txtCompHomeTel.Text = Convert.ToString(Session["Tel"]);
        }

        protected void cmdSave_Click(object sender, EventArgs e)
        {
            string sTel = Request.QueryString["type"] == "2" ? this.txtCompHomeTel.Text.Trim() : this.txtHomeTel.Text.Trim();
            string sRepRmk = Request.QueryString["type"] == "2" ? this.txtCompRepRmk1.Text.Trim() : this.txtRepRmk1.Text.Trim();
            string sRepSomething = Request.QueryString["type"] == "2" ? this.txtCompRepSomething.Text.Trim() : this.txtRepSomething.Text.Trim();
            bool bSmsflag = Request.QueryString["type"] == "2" ? this.radCompSmsY.Checked : this.radSmsY.Checked;

            DataAccess.PmData dal = new DataAccess.PmData();
            if (Request.QueryString["type"] == "2")
            {
                if (dal.Add_face_m_complaints(int.Parse(Session["CommId"].ToString()), int.Parse(Session["BuildId"].ToString()), int.Parse(Session["UnitId"].ToString()),
                    int.Parse(Session["EmpId"].ToString()), Session["Name"].ToString(), Session["Name"].ToString(), DateTime.Now, sTel, sRepRmk, sRepSomething, bSmsflag))
                {
                    ClientScript.RegisterClientScriptBlock(typeof(string), "1", "<script language=javascript>alert('提交成功！');window.location.href='ServicesList.aspx?type=" + Request.QueryString["type"] + "';</script>");
                }
                
            }
            else
            {
                if (dal.Add_face_m_repair(int.Parse(Session["CommId"].ToString()), int.Parse(Session["BuildId"].ToString()), int.Parse(Session["UnitId"].ToString()),
                                   int.Parse(Session["EmpId"].ToString()), Session["Name"].ToString(), Session["Name"].ToString(), DateTime.Now, sTel, sRepRmk, sRepSomething, bSmsflag))
                {
                    ClientScript.RegisterClientScriptBlock(typeof(string), "1", "<script language=javascript>alert('提交成功！');window.location.href='ServicesList.aspx?type=" + Request.QueryString["type"] + "';</script>");
                }
            }
        }
    }
}